<div class="container-xl">
  <!-- Page title -->
  <div class="page-header d-print-none">
    <div class="row align-items-center">
      <div class="col">
        <h2 class="page-title">
          基础设置
        </h2>
      </div>
    </div>
  </div>
</div>
<!-- 业务页面代码 -->
<div class="page-body">
  <div class="container-xl">
    <div class="row row-cards">
      <div class="col-md-12">
        <div class="card" id="basic_system">
          <div class="card-header">
            <h3 class="card-title"><strong>系统</strong><small style="color: red"> * 修改设置后需要重启生效</small></h3>
          </div>
          <div class="card-body">
            <div class="row">
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label required">日志输出类型</label>
                  <select class="form-select" id="app.logtype">
                    <option value="file" {% if Config.app.logtype=='file' %}selected{% endif %}>文件</option>
                    <option value="server" {% if Config.app.logtype=='server' %}selected{% endif %}>日志中心</option>
                  </select>
                </div>
              </div>
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label">日志文件路径 <span class="form-help bg-red-lt" title="日志输出类型为文件时需要配置该项" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.app.logpath or '' }}" class="form-control" id="app.logpath" placeholder="/config/logs" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label">日志中心地址 <span class="form-help bg-red-lt" title="日志输出类型为日志中心时需要配置该项；需要配置IP地址和端口，配置示例：127.0.0.1:514" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.app.logserver or '' }}" class="form-control" id="app.logserver" placeholder="127.0.0.1:514" autocomplete="false">
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label required">WEB服务端口</label>
                  <input type="text" value="{{ Config.app.web_port or '' }}" class="form-control" id="app.web_port" placeholder="3000" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label required">WEB管理用户</label>
                  <input type="text" value="{{ Config.app.login_user or '' }}" class="form-control" id="app.login_user" placeholder="admin" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label required">WEB管理密码</label>
                  <input type="password" value="{{ Config.app.login_password or '' }}" class="form-control" id="app.login_password" placeholder="password" autocomplete="false">
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label">HTTPS证书文件路径 <span class="form-help bg-red-lt" title="需要是pem格式的证书文件" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.app.ssl_cert or '' }}" class="form-control" id="app.ssl_cert" placeholder="" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label">HTTPS证书密钥文件路径</label>
                  <input type="text" value="{{ Config.app.ssl_key or '' }}" class="form-control" id="app.ssl_key" placeholder="" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label">代理服务器 <span class="form-help bg-red-lt" title="将使用代理访问tmdb、telegram等境外网站，PT站不使用代理；配置格式示例：http://127.0.0.1:7890、socks5://127.0.0.1:8018" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Proxy or '' }}" class="form-control" id="app.proxies" placeholder="http://127.0.0.1:7890" autocomplete="false">
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label">外网访问地址 <span class="form-help bg-red-lt" title="使用该地址进行通知点击跳转以及设置Telegram机器人Webhook；需要配置IP地址和端口，如为https则需要加https://前缀；如启用Telegram机器人Webhook，则端口必须为：443, 80, 88, 8443之一，80、443一般运营商会封禁，建议使用88、8443" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.app.domain or '' }}" class="form-control" id="app.domain" placeholder="http://IP:PORT" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-8">
                <div class="mb-3">
                  <label class="form-label">User-Agent <span class="form-help bg-red-lt" title="如发现被豆瓣、PT站等封堵，请适当修改此项" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.app.user_agent or '' }}" class="form-control" id="app.user_agent" placeholder="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36" autocomplete="false">
                </div>
              </div>
            </div>
          </div>
          <div class="card-footer">
            <div class="row align-items-center">
              <div class="col"></div>
              <div class="col-auto">
                <a id="basic_system_btn" href="javascript:save_basic_config('basic_system')" class="btn btn-primary">
                  保存
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="col-md-12">
        <div class="card" id="basic_media">
          <div class="card-header">
            <h3 class="card-title"><strong>媒体</strong></h3>
          </div>
          <div class="card-body">
            <div class="row">
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label required">TMDB API Key <span class="form-help bg-red-lt" title="在themoviedb.org网站申请API Key，该项必须配置，否则所有功能无法正常运行" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.app.rmt_tmdbkey or '' }}" class="form-control" id="app.rmt_tmdbkey" placeholder="" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label required">TMDB匹配模式 <span class="form-help bg-red-lt" title="正常模式下会提升识别成功率，但也可能会导致误识别率增加；严格模式可以降低误识别率，但可能导致很多文件名/种子名中年份不正确的无法被识别（特别是剧集，需要是首播年份）" data-bs-toggle="tooltip">?</span></label>
                  <select class="form-select" id="app.rmt_match_mode">
                    <option value="normal" {% if Config.app.rmt_match_mode=='normal' %}selected{% endif %}>正常模式</option>
                    <option value="strict"{% if Config.app.rmt_match_mode=='strict' %}selected{% endif %}>严格模式</option>
                  </select>
                </div>
              </div>
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label required">文件转移方式 <span class="form-help bg-red-lt" title="硬链接模式要求源目录和目的目录或媒体库目录在一个磁盘分区或者存储空间/共享文件夹，Docker运行时需要直接映射源目录和目的目录或媒体库目录的上级目录，否则docker仍然会认为是跨盘" data-bs-toggle="tooltip">?</span></label>
                  <select class="form-select" id="app.rmt_mode">
                    <option value="link" {% if Config.sync.sync_mod=='link' %}selected{% endif %}>硬链接</option>
                    <option value="softlink" {% if Config.sync.sync_mod=='softlink' %}selected{% endif %}>软链接</option>
                    <option value="copy" {% if Config.sync.sync_mod=='copy' %}selected{% endif %}>复制</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label">二级分类策略 <span class="form-help bg-red-lt" title="电影/电视剧/动漫是否需要二级分类，启用二级分类后会在电影/电视剧/动漫目录下按二级分类名建立子目录；此处配置分类的策略名，配置文件目录中需要有与策略名同名的.yaml配置文件，默认策略default-category分类设置可参考default-category.yaml；如不需要启动分类，则该项配置为空" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.media.category or '' }}" class="form-control" id="media.category" placeholder="default-category" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label required">媒体转移最小文件大小(MB) <span class="form-help bg-red-lt" title="小于该大小的文件将会忽略，不进行转移重命名" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.media.min_filesize or '' }}" class="form-control" id="media.min_filesize" placeholder="200" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-label required">下载优先规则 <span class="form-help bg-red-lt" title="订阅及远程搜索下载将按此优先规则选择下载资源，其中站点优先决定于维护的站点优先级或索引器中配置的站点顺序，默认为站点优先" data-bs-toggle="tooltip">?</span></label>
                  <select class="form-select" id="pt.download_order">
                    <option value="" {% if not Config.pt.download_order %}selected{% endif %}>默认</option>
                    <option value="site" {% if Config.pt.download_order=='site' %}selected{% endif %}>站点优先</option>
                    <option value="seeder" {% if Config.pt.download_order=='seeder' %}selected{% endif %}>做种数优先</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col">
                <div class="mb-3">
                  <label class="form-label required">电影重命名格式 <span class="form-help bg-red-lt" title="程序会按定义的命名格式对电影进行重命名；/代表上下级目录，{}内为占位符；占位符会使用文件识别出来的实际值替换；占位符外的字符会当成普通字符，直接体现在名称上&#10;电影占位符：{title}：标题，{year}：年份，{edition}：版本(Bluray/WEB-DL等)，{videoFormat}：分辨率(1080p/4k等)，{videoCodec}：视频编码，{audioCodec}：音频编码及声道，{tmdbid}：TMDB的ID，{part}：part1/disc1/dvd1等" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.media.movie_name_format or '' }}" class="form-control" id="media.movie_name_format" placeholder="{title} ({year})/{title}-{part} ({year}) - {videoFormat}" autocomplete="false">
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col">
                <div class="mb-3">
                  <label class="form-label required">电视剧重命名格式 <span class="form-help bg-red-lt" title="程序会按定义的命名格式对电视剧进行重命名；/代表上下级目录，{}内为占位符；占位符会使用文件识别出来的实际值替换，占位符外的字符会当成普通字符，直接体现在名称上&#10;电视剧占位符：{title}：标题，{year}：年份，{edition}：版本(Bluray/WEB-DL等)，{videoFormat}：分辨率(1080p/4k等)，{videoCodec}：视频编码，{audioCodec}：音频编码及声道，{tmdbid}：TMDB的ID，{season}：季数，{episode}：集数，{season_episode}：剧集SxxExx，{part}：part1/disc1/dvd1等" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.media.tv_name_format or '' }}" class="form-control" id="media.tv_name_format" placeholder="{title} ({year})/Season {season}/{title}-{part} - {season_episode} - 第 {episode} 集" autocomplete="false">
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" id="media.filesize_cover" {% if Config.media.filesize_cover %}checked{% endif %}>
                    <span class="form-check-label">高质量文件覆盖 <span class="form-help bg-red-lt" title="开启后，如下载了更高质量的同名文件时，会覆盖媒体库中已有的文件，否则不会进行转移处理" data-bs-toggle="tooltip">?</span></span>
                  </label>
                </div>
              </div>
              <div class="col-xl-4">
                <div class="mb-3">
                  <label class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" id="media.nfo_poster" {% if Config.media.nfo_poster %}checked{% endif %}>
                    <span class="form-check-label">生成NFO及海报 <span class="form-help bg-red-lt" title="开启后，会自动生成nfo描述文件及poster海报，协助媒体服务器识别和搜刮" data-bs-toggle="tooltip">?</span></span>
                  </label>
                </div>
              </div>
            </div>
          </div>
          <div class="card-footer">
            <div class="row align-items-center">
              <div class="col"></div>
              <div class="col-auto">
                <a id="basic_media_btn" href="javascript:save_basic_config('basic_media')" class="btn btn-primary">
                  保存
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="col-md-12">
        <div class="card" id="basic_service">
          <div class="card-header">
            <h3 class="card-title"><strong>服务</strong></h3>
          </div>
          <div class="card-body">
            <div class="row">
              <div class="col-xl-3">
                <div class="mb-3">
                  <label class="form-label">PT站自动签到时间 <span class="form-help bg-red-lt" title="PT站自动签到时间，两种配置方法：1、配置间隔，单位小时，比如23.5；2、配置固定时间，如08:00；配置为空则不启用自动PT站签到功能（有的站点不支持签到，仅登录一次网站保号）" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.pt.ptsignin_cron or '' }}" class="form-control" id="pt.ptsignin_cron" placeholder="留空关闭自动签到" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-3">
                <div class="mb-3">
                  <label class="form-label">RSS订阅检查周期(秒) <span class="form-help bg-red-lt" title="RSS订阅刷新的时间间隔，需要在订阅管理中设置订阅站点；如配置为空则不启动RSS订阅功能" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.pt.pt_check_interval or '' }}" class="form-control" id="pt.pt_check_interval" placeholder="留空关闭RSS订阅" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-3">
                <div class="mb-3">
                  <label class="form-label">订阅定时搜索周期(天) <span class="form-help bg-red-lt" title="定时对订阅内容进行存量资源搜索，以天为单位，最小间隔为1天，该项会对PT站造成搜索压力，如非必要请不要开启" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.pt.search_rss_interval or '' }}" class="form-control" id="pt.search_rss_interval" placeholder="留空关闭订阅定时搜索" autocomplete="false">
                </div>
              </div>
              <div class="col-xl-3">
                <div class="mb-3">
                  <label class="form-label">PT保种时间(天) <span class="form-help bg-red-lt" title="达到保种时间时将自动删除种子及对应的文件；如配置为空则不启动自动删种功能" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.pt.pt_seeding_time or '' }}" class="form-control" id="pt.pt_seeding_time" placeholder="留空关闭定时删种" autocomplete="false">
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xl-3">
                <div class="mb-3">
                  <label class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" id="pt.pt_monitor" {% if Config.pt.pt_monitor %}checked{% endif %}>
                    <span class="form-check-label">下载软件监控 <span class="form-help bg-red-lt" title="监控下载软件，下载完成后自动进行文件转移。与目录同步监控下载目录二选一开启" data-bs-toggle="tooltip">?</span></span>
                  </label>
                </div>
              </div>
              <div class="col-xl-3">
                <div class="mb-3">
                  <label class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" id="pt.pt_monitor_only" {% if Config.pt.pt_monitor_only %}checked{% endif %}>
                    <span class="form-check-label">只管理NASTool添加的下载 <span class="form-help bg-red-lt" title="启用后只有NASTool添加的下载才会被自动转移和显示，关闭则下载软件中所有的任务都会转移和显示" data-bs-toggle="tooltip">?</span></span>
                  </label>
                </div>
              </div>
              <div class="col-xl-3">
                <div class="mb-3">
                  <label class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" id="pt.search_auto" {% if Config.pt.search_auto %}checked{% endif %}>
                    <span class="form-check-label">远程搜索自动择优下载 <span class="form-help bg-red-lt" title="启用后在微信、Telegram发送名称后会自动择优下载，否则需要点击链接跳转后手工选择" data-bs-toggle="tooltip">?</span></span>
                  </label>
                </div>
              </div>
              <div class="col-xl-3">
                <div class="mb-3">
                  <label class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" id="pt.search_no_result_rss" {% if Config.pt.search_no_result_rss %}checked{% endif %}>
                    <span class="form-check-label">远程搜索无结果添加订阅 <span class="form-help bg-red-lt" title="启用后在微信、Telegram发送名称搜索无结果时将自动添加订阅" data-bs-toggle="tooltip">?</span></span>
                  </label>
                </div>
              </div>
            </div>
          </div>
          <div class="card-footer">
            <div class="row align-items-center">
              <div class="col"></div>
              <div class="col-auto">
                <a id="basic_service_btn" href="javascript:save_basic_config('basic_service')" class="btn btn-primary">
                  保存
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="col-md-12">
        <div class="card" id="security">
          <div class="card-header">
            <h3 class="card-title"><strong>安全</strong></h3>
          </div>
          <div class="card-body">
            <div class="row">
              <div class="col-12 col-xl-4">
                <div class="mb-1">
                  <label class="form-label">媒体服务器Webhook源地址 <span class="form-help bg-red-lt" title="仅允许配置的地址范围内地址调用Webhook，多个地址段用,号分隔，默认为0.0.0.0/0,::/0即不做限制" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{{ Config.security.media_server_webhook_allow_ip.ipv4 or '' }}" class="form-control" id="security.media_server_webhook_allow_ip.ipv4" placeholder="允许的IPv4 CIDR" autocomplete="false">
                </div>
                <div class="mb-3">
                  <input type="text" value="{{ Config.security.media_server_webhook_allow_ip.ipv6 or '' }}" class="form-control" id="security.media_server_webhook_allow_ip.ipv6" placeholder="允许的IPv6 CIDR" autocomplete="false">
                </div>
              </div>
              <div class="col-12 col-xl-4">
                <div class="mb-1">
                  <label class="form-label">Telegram Webhook源地址 <span class="form-help bg-red-lt" title="仅允许配置的地址范围内地址调用Webhook，多个地址段用,号分隔，配置为0.0.0.0/0,::/0则不做限制" data-bs-toggle="tooltip">?</span></label>
                  <input type="text" value="{% if Config.security.telegram_webhook_allow_ip %}{{ Config.security.telegram_webhook_allow_ip.ipv4 or '' }}{% endif %}" class="form-control" id="security.telegram_webhook_allow_ip.ipv4" placeholder="允许的IPv4 CIDR" autocomplete="false">
                </div>
                <div class="mb-3">
                  <input type="text" value="{% if Config.security.telegram_webhook_allow_ip %}{{ Config.security.telegram_webhook_allow_ip.ipv6 or '' }}{% endif %}" class="form-control" id="security.telegram_webhook_allow_ip.ipv6" placeholder="允许的IPv6 CIDR" autocomplete="false">
                </div>
              </div>
            </div>
          </div>
          <div class="card-footer">
            <div class="row align-items-center">
              <div class="col"></div>
              <div class="col-auto">
                <a id="security_btn" href="javascript:save_basic_config('security')" class="btn btn-primary">
                  保存
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="col-md-12">
        <div class="card" id="laboratory">
          <div class="card-header">
            <h3 class="card-title"><strong>实验室</strong></h3>
          </div>
          <div class="card-body">
            <div class="row">
              <div class="col-12 col-xl-3">
                <div class="mb-3">
                  <label class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" id="laboratory.search_keyword" {% if Config.laboratory and Config.laboratory.search_keyword %}checked{% endif %}>
                    <span class="form-check-label">辅助识别 <span class="form-help bg-red-lt" title="开启后，无法识别到媒体信息时会尝试猜测和纠正关键词并再次匹配，可能会增加识别耗时" data-bs-toggle="tooltip">?</span></span>
                  </label>
                </div>
              </div>
              <div class="col-12 col-xl-3">
                <div class="mb-3">
                  <label class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" id="laboratory.tmdb_cache_expire" {% if Config.laboratory and Config.laboratory.tmdb_cache_expire %}checked{% endif %}>
                    <span class="form-check-label">TMDB缓存过期策略 <span class="form-help bg-red-lt" title="开启TMDB缓存过期策略后，默认7天过期，过期缓存将被删除,  7天内访问过期时间可以被刷新" data-bs-toggle="tooltip">?</span></span>
                  </label>
                </div>
              </div>
              <div class="col-12 col-xl-3">
                <div class="mb-3">
                  <label class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" id="laboratory.use_douban_titles" {% if Config.laboratory and Config.laboratory.use_douban_titles %}checked{% endif %}>
                    <span class="form-check-label">使用豆瓣名称联想 <span class="form-help bg-red-lt" title="开启将使用豆瓣进行电影电视剧的名称联想，否则使用TMDB的数据" data-bs-toggle="tooltip">?</span></span>
                  </label>
                </div>
              </div>
              <div class="col-12 col-xl-3">
                <div class="mb-3">
                  <label class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" id="laboratory.search_en_title" {% if Config.laboratory and Config.laboratory.search_en_title %}checked{% endif %}>
                    <span class="form-check-label">精确搜索使用英文名称 <span class="form-help bg-red-lt" title="开启后对于精确搜索场景（远程搜索、订阅搜索等）将会使用英文名检索站点资源以提升匹配度，但对有些站点资源标题全是中文的则需要关闭，否则匹配不到" data-bs-toggle="tooltip">?</span></span>
                  </label>
                </div>
              </div>
            </div>
          </div>
          <div class="card-footer">
            <div class="row align-items-center">
              <div class="col"></div>
              <div class="col-auto">
                <a id="laboratory_btn" href="javascript:save_basic_config('laboratory')" class="btn btn-primary">
                  保存
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
  function save_basic_config(type){
    var params = {};
    $("#"+ type +" input").each(function(){
      var key = $(this).attr("id");
      if($(this).attr("type")=="checkbox"){
        var value = $(this).prop("checked") ? true:false;
      }else{
        var value = $(this).val();
      }
      params[key] = value;
    });
    $("#"+ type +" select").each(function(){
      var key = $(this).attr("id");
      var value = $(this).val();
      params[key] = value;
    });
    $("#"+ type +"_btn").attr("disabled", true);
    $("#"+ type +"_btn").text("保存中...");
    ajax_post("update_config", params, function (ret) {
      $("#"+ type +"_btn").attr("disabled", false);
      $("#"+ type +"_btn").text("保存");
    });
  }
</script>